package com.visec.hdy.file;

import java.io.File;
import java.io.InputStream;
import java.util.List;

import com.visec.hdy.hadoop.standard.FSB;
import com.visec.hdy.hadoop.standard.Inquiry;

public interface HFile<K, V> {
	public enum SystemType {
		FAT, FAT32, NTFS;
		public long maxSize() {
			if (SystemType.FAT32 == this)
				return 65536;
			if (SystemType.NTFS == this)
				return 4294967295l;
			return 512;
		}
	}

	void save(V v);

	Find findAll();

	Find find(K k);

	void close();

	public class Find {
		private Inquiry<String, File> inquiry;
		private FSB fsb;

		public Find(Inquiry<String, File> inquiry, FSB fsb) {
			this.inquiry = inquiry;
			this.fsb = fsb;
		}

		public File next() {
			List<File> next = this.inquiry.next(1, File.class);
			return next.isEmpty()?null:next.get(0);
		}

		public InputStream getNext() {
			File next = next();
			return next == null ? null : this.fsb.get(next);
		}

		public List<File> next(int i) {
			return this.inquiry.next(i, File.class);
		}

		public InputStream get(File file) {
			return this.fsb.get(file);
		}

		public long getCount() {
			return this.inquiry.count();
		}
	}
}
